const path = require("path");
const HhtmlWebpackPlugin = require("html-webpack-plugin");  // --自动生成html文件
const TerserPlugin = require("terser-webpack-plugin");// --代码压缩
const BundleAnalyzerPlugin =
  require("webpack-bundle-analyzer").BundleAnalyzerPlugin;// --打包分析
const ESLintPlugin = require("eslint-webpack-plugin"); // --eslint代码检查
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
module.exports = {
  entry: "./src/player/index.js",
  output: {
    filename: "[name].[contenthash].js",
    path: path.resolve(__dirname, "dist"),
  },
  optimization: {
    minimize: true, // 启用压缩
    minimizer: [
      new TerserPlugin({
        terserOptions: {
          compress: true, // 启用压缩
          mangle: true, // 启用变量名混淆
          output: {
            comments: true, // 移除注释
          },
        },
      }),
    ],
  },
  plugins: [
    new CleanWebpackPlugin(),
    new HhtmlWebpackPlugin({
      title: "Movie App",
    }),
    new BundleAnalyzerPlugin({
      analyzerMode: "static", // 生成静态文件
    }),
    new ESLintPlugin({
      context: "src", // 检查的目录
      extensions: ["js", "jsx", "ts", "tsx"], // 检查的文件扩展名
      fix: true, // 自动修复问题
      emitWarning: true,
    }),
  ],
  module: {
    rules: [
      {
        test: /\.css$/,
        use: ["style-loader", "css-loader"],
      },
      {
        test: /\.(png|svg|jpg|jpeg|gif|mp3)$/,
        use: ["file-loader"],
      },
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader",
          options: {
            presets: ["@babel/preset-env"],
          },
        },
      },
    ],
  },
  devServer: {
    static: "./dist",
  },
  devtool: "inline-source-map",
  mode: "development",
};
